package cn.initcap.algorithm.data.structures.trie;

import cn.initcap.algorithm.data.structures.set.BinarySearchTreeSet;
import cn.initcap.algorithm.data.structures.set.FileOperation;
import java.util.ArrayList;

/**
 * @author initcap
 * @date Created in 2018/6/29 PM1:16.
 */
public class Test {

    public static void main(String[] args) {
        System.out.println("Pride and Prejudice");

        ArrayList<String> words = new ArrayList<>();
        if (FileOperation.readFile("algorithm/pride-and-prejudice.txt", words)) {

            long startTime = System.nanoTime();

            BinarySearchTreeSet<String> set = new BinarySearchTreeSet<>();
            for (String word : words) {
                set.add(word);
            }
            for (String word : words) {
                set.contains(word);
            }
            long endTime = System.nanoTime();

            double time = (endTime - startTime) / 1000000000.0;

            System.out.println("Total different words: " + set.getSize());
            System.out.println("BSTSet: " + time + " s");

            // ---

            startTime = System.nanoTime();

            Trie trie = new Trie();
            for (String word : words) {
                trie.add(word);
            }
            for (String word : words) {
                trie.contains(word);
            }
            endTime = System.nanoTime();

            time = (endTime - startTime) / 1000000000.0;

            System.out.println("Total different words: " + trie.getSize());
            System.out.println("Trie: " + time + " s");
        }
    }
}
